"""
auth : ginger
    从配日志文件获取 cookie 信息
    写入配志文件 cookie 信息
"""
from common.do_file_path import COOKIE_CONF_PATH
from common.do_log import do_log


def get_cookies():
    file_info = open(COOKIE_CONF_PATH, mode='r', encoding='utf-8').read()
    do_log.info('从配置文件读取 Cookie 信息为 :' + file_info)
    return file_info


def write_cookies(cookie):
    f = open(COOKIE_CONF_PATH, mode='w', encoding='utf8')
    f.write(cookie)
    f.close()
    do_log.info('写入 Cookie 到配置文件成功 : ' + cookie)


def get_cookies_to_dict():
    file_info = open(COOKIE_CONF_PATH, mode='r', encoding='utf-8').read()
    di = {'Cookie': file_info}
    do_log.info('Cookie 字典信息 : ' + str(di))
    return di


if __name__ == '__main__':
    write_cookies(cookie='SESSION=ZjlkY2NlYjUtMTcyNi00NjVlLTg0ZTAtNDkxZTliZmNmZDg2')
    cookies = get_cookies()

    write_cookies(cookie='SESSION=YmQwNTIyZGMtMTgwNy00MWU1LTllNWUtYzY0ZTFiMGViNzYw')
    cookies = get_cookies()

    cookies_dict = get_cookies_to_dict()
